﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentSerialVMs
{
    public partial class EquipmentSerialListVM : BasePagedListVM<EquipmentSerial_View, EquipmentSerialSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EquipmentSerial_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentSerial_View>>{

                 this.MakeGridHeader(x => x.EquipmentSerial_EquipmentId).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_Equipment).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_SerialName).SetTitle(@Localizer["Page.串口"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_Description).SetTitle(@Localizer["Page.说明"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_BaudRate).SetTitle(@Localizer["Page.波特率"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_DataLength).SetTitle(@Localizer["Page.数据长度"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_StopBit).SetTitle(@Localizer["Page.停止位"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_Parity).SetTitle(@Localizer["Page.奇偶校验"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_Threshold).SetTitle(@Localizer["Page.最小长度"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_TagId).SetTitle(@Localizer["Page.链接Tag"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_TagName).SetTitle(@Localizer["Page.标记名称"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_GlobalPushlish).SetTitle(@Localizer["Page.全局发布"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentSerial_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipmentSerial_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentSerial>()
                
                .CheckEqual(Searcher.EquipmentId, x=>x.EquipmentId)
                .CheckContain(Searcher.SerialName, x=>x.SerialName)
                .CheckContain(Searcher.Description, x=>x.Description)
                .CheckEqual(Searcher.BaudRate, x=>x.BaudRate)
                .CheckEqual(Searcher.DataLength, x=>x.DataLength)
                .CheckEqual(Searcher.StopBit, x=>x.StopBit)
                .CheckEqual(Searcher.Parity, x=>x.Parity)
                .CheckEqual(Searcher.Threshold, x=>x.Threshold)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckEqual(Searcher.TagId, x=>x.TagId)
                .CheckContain(Searcher.TagName, x=>x.TagName)
                .CheckEqual(Searcher.GlobalPushlish, x=>x.GlobalPushlish)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new EquipmentSerial_View
                {
				    ID = x.ID,
                    
                    EquipmentSerial_Equipment = x.Equipment.EquipName,
                    EquipmentSerial_SerialName = x.SerialName,
                    EquipmentSerial_EquipmentId=x.EquipmentId,
                    EquipmentSerial_Description = x.Description,
                    EquipmentSerial_BaudRate = x.BaudRate,
                    EquipmentSerial_DataLength = x.DataLength,
                    EquipmentSerial_StopBit = x.StopBit,
                    EquipmentSerial_Parity = x.Parity,
                    EquipmentSerial_Threshold = x.Threshold,
                    EquipmentSerial_Active = x.Active,
                    EquipmentSerial_TagId = x.TagId,
                    EquipmentSerial_TagName = x.TagName,
                    EquipmentSerial_GlobalPushlish = x.GlobalPushlish,
                    EquipmentSerial_CreateTime = x.CreateTime,
                    EquipmentSerial_UpdateTime = x.UpdateTime,
                    EquipmentSerial_CreateBy = x.CreateBy,
                    EquipmentSerial_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EquipmentSerial_View: EquipmentSerial
    {
        public long? EquipmentSerial_EquipmentId { get; set; }

        public string EquipmentSerial_Equipment { get; set; }
        public string EquipmentSerial_SerialName { get; set; }
        public string EquipmentSerial_Description { get; set; }
        public int? EquipmentSerial_BaudRate { get; set; }
        public int? EquipmentSerial_DataLength { get; set; }
        public decimal? EquipmentSerial_StopBit { get; set; }
        public int? EquipmentSerial_Parity { get; set; }
        public int? EquipmentSerial_Threshold { get; set; }
        public bool? EquipmentSerial_Active { get; set; }
        public long? EquipmentSerial_TagId { get; set; }
        public string EquipmentSerial_TagName { get; set; }
        public bool? EquipmentSerial_GlobalPushlish { get; set; }
        public DateTime? EquipmentSerial_CreateTime { get; set; }
        public DateTime? EquipmentSerial_UpdateTime { get; set; }
        public string EquipmentSerial_CreateBy { get; set; }
        public string EquipmentSerial_UpdateBy { get; set; }

    }

}